#!/bin/bash
set -e

while getopts  ":s:p:" opts
do
        case  $opts  in
        s)
		sample_name=$OPTARG
		;;
		p)
		out_prefix=$OPTARG	
		;;
        esac
done
shift $(($OPTIND - 1))

if [ -z "$1" ]; then
	echo `basename $0` '[-p out_prefix] in.vcf'
	exit 1
fi

#-----------------------------------------------
#-----------------------------------------------
. /mnt/ilustre/app/medical/tools/.var #---------
#-----------------------------------------------

echo DP
java $j_mem -jar $snpsift extractField $1 DP > $out_prefix.dp.txt

echo extractField $1 GEN[0].AD[*]
java $j_mem -jar $snpsift extractField $1 "GEN[0].AD[*]" > $out_prefix.ref.alt.dp.txt

paste $out_prefix.ref.alt.dp.txt $out_prefix.dp.txt > $out_prefix.all_dp.txt

# 删除第一行的注释用于计算
sed -i "1d" $out_prefix.all_dp.txt

echo format depth
perl $script_path/format_0318.pl $out_prefix.all_dp.txt > $out_prefix.all.frq.txt

cut -f2 $out_prefix.all.frq.txt > $out_prefix.af0.txt

# sed -i '1i ##INFO=<ID=af,Number=1,Type=Float,Description="Allele frequency">' $out_prefix.af.txt # if file is empty, it will do nothing. it's a bug

echo '##INFO=<ID=af,Number=1,Type=Float,Description="Allele frequency">' |cat - $out_prefix.af0.txt > $out_prefix.af.txt

# echo '##INFO=<ID=af,Number=1,Type=Float,Description="Allele frequency">' |cat - $(cut -f2 1.all.frq.txt) > 1.af.txt


. $cmd_done